<!--
 * @Descripttion: 日期时间
 * @Author: zhoujj
 * @Date: 2021-07-05 16:00:14
 * @LastEditors: zhoujj
 * @LastEditTime: 2021-07-06 17:42:48
-->
<template>
  <div v-if="item">
    <el-form ref="form" :rules="rules" :model="form" label-width="120px">
      <el-form-item :label="item.title" prop="value">
        <el-date-picker
          v-model="form.value"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          :placeholder="item.msg"
          @change="getVal"
        >
        </el-date-picker>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  props: ["item", "number"],
  data() {
    return {
      form: {
        value: "",
      },
      rules: {
        value: [
          {
            required: this.item.must,
            message: this.item.msg,
            trigger: "change",
          },
        ],
      },
    };
  },
  methods: {
    getVal(val) {
      if (val.length !== 0) {
        this.$refs["form"].clearValidate();
      }
      this.form.value = val;
      this.$emit("changeComponent", {
        number: this.number,
        type: this.item.type,
        value: this.form.value,
      });
    },
  },
  mounted() {
    this.form = {
      ...this.form,
      ...this.item,
    };
  },
};
</script>

<style></style>
